using UnityEngine;
using System.Collections.Generic;

public class BulletHitPool : Singleton<BulletHitPool>
{
    public GameObject BulletHitPrefab;

    public Queue<GameObject> _queue;

    public int InitNumber = 20;

    private void Start()
    {
        _queue = new Queue<GameObject>();
    }

    public GameObject GetBulletHit()
    {
        GameObject b;
        if (_queue.Count > 0)
        {
            b = _queue.Dequeue();
            b.SetActive(true);
        }
        else
        {
            b = Instantiate(BulletHitPrefab, transform);
            if (_queue.Count < InitNumber)
            {
                _queue.Enqueue(b);
            }
        }
        return b;
    }

    public void RecoverBulletHit(GameObject b)
    {
        _queue.Enqueue(b);
    }
}
